import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.util.Date;

public class J_BufferedInputStream
{
	private static String m_fileName="J_BufferedInputStream.class";

	public static void main(String[] args)
	{
		try
		{
			int i,ch;
			i=0;
			Date d1=new Date();
			FileInputStream f=new FileInputStream(m_fileName);
			while ((ch=f.read())!=-1)
				i++;
			f.close();
			Date d2=new Date();

			long t=d2.getTime()-d1.getTime();  //ms
			System.out.printf("读取文件%1$s(共%2$d字节)%n",m_fileName,i);
			System.out.printf("不带缓存的方法需要%1$dms%n",t);

			i=0;
			d1=new Date();
			f=new FileInputStream(m_fileName);
			BufferedInputStream fb=new BufferedInputStream(f);
			while ((ch=fb.read())!=-1)
				i++;
			fb.close();
			d2=new Date();
			t=d2.getTime()-d1.getTime();  //ms
			System.out.printf("带缓存的方法需要%1$dms%n",t);
		}
		catch (Exception e)
		{
			System.err.println("发生异常："+e);
			e.printStackTrace();
		}
	}
};